#include "BlockQueue.hpp"
#include <unistd.h>

void *Product(void *args)
{
    BlockQueue<int> *block = static_cast<BlockQueue<int> *>(args);
    int i = 1;
    while (1)
    {

        std::cout << "生产了一个任务" << std::endl;
        block->Equeue(++i);
    }

    return (void *)1;
}

void *Conmuse(void *args)
{

    BlockQueue<int> *block = static_cast<BlockQueue<int> *>(args);
    while (1)
    {
        sleep(2);
        block->Pop();
    }

    return (void *)1;
}

int main()
{
    BlockQueue<int> *block = new BlockQueue<int>();
    pthread_t c[2], p[3];
    pthread_create(&c[0], nullptr, Product, (void *)block);
    pthread_create(&c[1], nullptr, Product, (void *)block);
    pthread_create(&p[0], nullptr, Conmuse, (void *)block);
    pthread_create(&p[1], nullptr, Conmuse, (void *)block);
    pthread_create(&p[2], nullptr, Conmuse, (void *)block);

    pthread_join(c[0], nullptr);
    pthread_join(c[1], nullptr);
    pthread_join(p[0], nullptr);
    pthread_join(p[1], nullptr);
    pthread_join(p[2], nullptr);

    return 0;
}